package com.citicpub_cloud.restfull.utils;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.List;

public class CsvWriter extends BufferedWriter {

	public CsvWriter(Writer out) {
		super(out);
	}

	public void writeLine(List<String> csvLine) throws IOException {
		StringBuffer sb = new StringBuffer();

		for (int i = 0; i < csvLine.size(); i++) {
			String line = csvLine.get(i);
			if (line == null) {
				line = "";
			}
			sb.append("\"").append(line.replaceAll("\"", "\"\"")).append("\",");
		}

		if(sb.length()>0){
			super.write(sb.deleteCharAt(sb.length() - 1).toString());
		}
		super.newLine();
	}

}
